package com.zcx.qshop.conn;

import com.zcx.helper.http.AsyCallBack;
import com.zcx.helper.http.note.HttpInlet;
import com.zcx.qshop.entity.Good;

import org.json.JSONArray;
import org.json.JSONObject;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 2015/11/16.
 */
@HttpInlet(Conn.INLET_JSON_ORDERINFO)
public class JsonOrderinfoAsyGet extends QSAsyGet<JsonOrderinfoAsyGet.Info> {

    public String orderid;
;
    public JsonOrderinfoAsyGet(String orderid, AsyCallBack<Info> asyCallBack) {

        super(asyCallBack);

        this.orderid = orderid;

    }

    @Override
    protected Info parser(JSONObject object) {

        if(object.optString("message").equals("1")){

            Info info = new Info();

            info.posttime = object.optString("posttime");

            info.type = object.optString("type");

            info.checkinfo = object.optString("checkinfo");

            info.name = object.optString("name");

            info.mobile = object.optString("mobile");

            info.address = object.optString("address");

            info.number = object.optString("number");

            info.acount = object.optString("acount");

            info.cnumber = object.optString("cnumber");

            JSONObject o1 = object.optJSONObject("coupon");

            if(o1 != null){

                info.coupon = new JsonCouponAsyGet.Info.Coupon();

                info.coupon.cid = o1.optString("couponid");

                info.coupon.price = o1.optString("price");

                info.coupon.fullprice = o1.optString("fullprice");

                info.coupon.begintime = o1.optString("begintime");

                info.coupon.endtime = o1.optString("endtime");

                info.coupon.statue = o1.optString("type");

            }

            JSONArray array = object.optJSONArray("goodslist");

            for (int i = 0 ; i < array.length() ; i ++){

                JSONObject o = array.optJSONObject(i);

                Good good = new Good();

                good.title = o.optString("title");

                good.picurl = Conn.SERVICE + o.optString("picurl");

                good.unit = o.optString("unit");

                good.price = o.optString("price");

                good.number = o.optString("number");

                info.goods.add(good);

            }

            return info;

        }

        return null;

    }

    public static class Info{

        public String posttime, type, checkinfo, name, mobile, address, number, acount, cnumber;

        public JsonCouponAsyGet.Info.Coupon coupon;

        public List<Good> goods = new ArrayList<>();

    }

}
